package org.basis.algorithm.lru;


import java.util.HashSet;

/**
 * lru测试
 *
 * @author Mr_wenpan@163.com 2022/01/02 15:51
 */
public class LruTest {

    public static void main(String[] args) {
        lruTest01();

        String str = "wen.pan.feng.hello.world";
        str = str.replace(".", "");
        System.out.println(str);

        String[] strs = new String[]{"test.email+alex@leetcode.com", "test.email.leet+alex@code.com"};
        int i = numUniqueEmails(strs);
        System.out.println(i);
    }

    public static void lruTest01() {
        MyLru01 map = new MyLru01(10);
        map.put("wenpan-1", "wenpan-1");
        String str = map.get("wenpan-1");
        System.out.println(str);
    }

    public static void lruTest02() {
        MyLru myLru = new MyLru(3);
        myLru.put("wenpan-1", "wenpan-1");
        myLru.put("wenpan-2", "wenpan-2");
        myLru.put("wenpan-3", "wenpan-3");
        myLru.put("wenpan-4", "wenpan-4");
        String res = myLru.get("wenpan-1");
        System.out.println(res);
        myLru.put("wenpan-5", "wenpan-5");
        myLru.put("wenpan-0", "wenpan-0");
    }

    public static int numUniqueEmails(String[] emails) {
        HashSet<String> set = new HashSet<>();
        for (String s : emails) {
            String[] split = s.split("@");
            String res = split[0].replace(".", "");
            int indexOf = res.indexOf("+");
            if (indexOf > 0) {
                res = res.substring(0, indexOf);
            }
            String email = res + "@" + split[1];
            set.add(email);
        }
        return set.size();
    }
}
